package com.example.second_home_work

import android.graphics.Color
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {

    private var context:MainActivity? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        context = this

        val addViewButton:Button? = findViewById<Button>(R.id.AddTextView);
        val convertButton:Button? = findViewById<Button>(R.id.ConvertButton)

        convertButton?.setOnClickListener {
            val spinner:Spinner? = findViewById<Spinner>(R.id.spinner)
            val selectedString = spinner?.selectedItem.toString()
            val convert = Convert()
            val targetTextView:TextView? = findViewById<TextView>(R.id.textView)
            targetTextView?.text = convert.convert(selectedString)
        }
        ;
        addViewButton?.setOnClickListener {
            val scrollView:LinearLayout? = findViewById<LinearLayout>(R.id.TextCollections)
            val textTemp:TextView =  TextView(context)
            textTemp.setText(R.string.textTemplate)
            scrollView?.addView(textTemp)
        }
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

    }
}